#ifndef OBJECT_3D_H
#define OBJECT_3D_H

#include "point3d.h"
#include <QString>

enum RotationType
{
  ROT_XY = 0x00f,
  ROT_XZ = 0x0f0,
  ROT_YZ = 0xf00,
};

class Matrix4x4
{
  friend Matrix4x4 operator * (const Matrix4x4 m1, const Matrix4x4& m2);
  friend void setGlModelViewMatrix(const Matrix4x4& m);
public:
  // Create identity matrix
  Matrix4x4();
  Matrix4x4(const Matrix4x4& m);
  ~Matrix4x4();

  float* operator [] (int i);
  Matrix4x4& operator = (const Matrix4x4& m);

  static Matrix4x4 translateMatrix(float x, float y, float z);
  static Matrix4x4 scaleMatrix(float sx, float sy, float sz);
  static Matrix4x4 rotateMatrix(float alpha, RotationType type);
private:
  float** data;
};

Matrix4x4 operator * (const Matrix4x4 m1, const Matrix4x4& m2);
void setGlModelViewMatrix(const Matrix4x4& m);

class AbstractObject3D
{
public:
  virtual void render() const = 0;
  void translate(float x, float y, float z);
  void rotate(float alpha, RotationType type);
  void zoom(float z);
  void transform(const Matrix4x4& m);
protected:
  Matrix4x4 worldMatrix;
};

class TrajectionObject3D : public AbstractObject3D
{
public:
  TrajectionObject3D(const QVector<Point3D>& pointList, Point3D center, float scale, int color);
  virtual void render() const;
private:
  QVector<Point3D> m_pointList;
  float cr, cg, cb;
};

class TextObject3D : public AbstractObject3D
{
public:
  TextObject3D(QString text);
  virtual void render() const;
private:
  QString m_text;
};

class PlanetObject3D : public AbstractObject3D
{
public:
  static const int DRAW_PLANET;
  static const int DRAW_TRAJECTORY;
  static const int DRAW_CAPTION;
public:
  PlanetObject3D(float r, QString name, const QVector<Point3D>& pointList, Point3D center, float scale, unsigned color);
  virtual void render() const;
  
  static int getDrawingType();
  static void setDrawingType(int dt);
private:
  float cr, cg, cb;
  TextObject3D caption;
  TrajectionObject3D trajectory;
  static int drawingType;
};






#endif // OBJECT_3D_H
